package co.yixiang.controller.manager.system;

import co.yixiang.common.utils.ResultUtil;
import co.yixiang.common.vo.ResultMessage;
import co.yixiang.modules.system.entity.vo.FreightTemplateVo;
import co.yixiang.modules.system.service.FreightTemplateService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import javax.validation.Valid;
import java.util.List;

@RestController
@Api(tags = "管理端,短信签名接口")
@RequestMapping("/api/freightTemplate")
public class FreightTemplateController {

    @Autowired
    private FreightTemplateService freightTemplateService;

    @ApiOperation(value = "商家运费模板列表")
    @GetMapping
    public ResultMessage<List<FreightTemplateVo>> list() {
        return ResultUtil.data(freightTemplateService.getFreightTemplateList(""));
    }

    @ApiOperation(value = "获取商家运费模板详情")
    @ApiImplicitParam(name = "id", value = "商家模板ID", required = true, paramType = "path")
    @GetMapping("/{id}")
    public ResultMessage<FreightTemplateVo> list(@PathVariable String id) {
        FreightTemplateVo freightTemplate = freightTemplateService.getFreightTemplate(id);
        return ResultUtil.data(freightTemplate);
    }

    @ApiOperation(value = "添加商家运费模板")
    @PostMapping
    public ResultMessage<FreightTemplateVo> add(@Valid @RequestBody FreightTemplateVo freightTemplateVO) {
        return ResultUtil.data(freightTemplateService.addFreightTemplate(freightTemplateVO));
    }

    @ApiOperation(value = "修改商家运费模板")
    @PutMapping("/{id}")
    public ResultMessage<FreightTemplateVo> edit(@PathVariable String id, @RequestBody @Valid FreightTemplateVo freightTemplateVo) {
        freightTemplateService.getFreightTemplate(id);

        return ResultUtil.data( freightTemplateService.editFreightTemplate(freightTemplateVo));
    }

    @ApiOperation(value = "删除商家运费模板")
    @ApiImplicitParam(name = "id", value = "商家模板ID", required = true, paramType = "path")
    @DeleteMapping("/{id}")
    public ResultMessage<Object> edit(@PathVariable String id) {
        freightTemplateService.getFreightTemplate(id);
        freightTemplateService.removeFreightTemplate(id);
        return ResultUtil.success();
    }
}
